package com.yijinsuo.activity;

import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;

import com.yijinsuo.R;
import com.yijinsuo.adapter.BaseFragmentAdapter;
import com.yijinsuo.base.BaseActivity;
import com.yijinsuo.base.SpulshBaseFragment;
import com.yijinsuo.fragment.SplashOneFragment;
import com.yijinsuo.fragment.SplashThreeFragment;
import com.yijinsuo.fragment.SplashTwoFragment;
import com.yijinsuo.tool.SharedPreferencesUtils;
import com.yijinsuo.view.GuideViewPager;

import java.util.ArrayList;
import java.util.List;
/**
 * 欢迎页
 */
public class SplashActivity extends BaseActivity {
//    private ImageView[] tips;
//    private int currentSelect;

    private GuideViewPager vPager;
    private List<SpulshBaseFragment> list = new ArrayList<SpulshBaseFragment>();
    private BaseFragmentAdapter adapter;

    //
    private SplashOneFragment oneFragment;
    private SplashTwoFragment toTwoFragment;
    private SplashThreeFragment threeFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_splash);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {



        SharedPreferencesUtils.getInstance().put(SplashActivity.this, "first", true);

    }

    @Override
    protected void initView() {



        //获取自定义viewpager 然后设置背景图片
        vPager = (GuideViewPager) findViewById(R.id.viewpager_launcher);
        vPager.setBackGroud(BitmapFactory.decodeResource(getResources(),R.mipmap.bg_kaka_launcher));
        /**
         * 初始化三个fragment  并且添加到list中
         */
        //
        oneFragment=new SplashOneFragment();
        toTwoFragment=new SplashTwoFragment();
        threeFragment=new SplashThreeFragment();
        list.add(oneFragment);
        list.add(toTwoFragment);
        list.add(threeFragment);
        adapter=new BaseFragmentAdapter(getSupportFragmentManager(), list);
        vPager.setAdapter(adapter);
        vPager.setOffscreenPageLimit(2);
        vPager.setCurrentItem(0);
        vPager.setOnPageChangeListener(changeListener);


    }

    /**
     * 监听viewpager的移动
     */
    OnPageChangeListener changeListener=new OnPageChangeListener() {
        @Override
        public void onPageSelected(int index) {
//            setImageBackground(index);//改变点点点的切换效果
            SpulshBaseFragment fragment=list.get(index);

//            list.get(currentSelect).stopAnimation();//停止前一个页面的动画
            fragment.startAnimation();//开启当前页面的动画

//            currentSelect=index;
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {}
        @Override
        public void onPageScrollStateChanged(int arg0) {}
    };



    @Override
    protected void setData() {

    }

    @Override
    public void widgetClick(View v) {

    }
}
